#include <myheader.h>

/* Usage:  */
int main(int argc, char *argv[]){                                  
    char*port="8080";
    char*ip="192.168.74.128";
    int socket_fd=socket(AF_INET,SOCK_STREAM,0);
    struct sockaddr_in client_sock;
    client_sock.sin_family=AF_INET;
    client_sock.sin_port=htons(atoi(port));
    client_sock.sin_addr.s_addr=inet_addr(ip);

    int ret=connect(socket_fd,(struct sockaddr*)&client_sock,sizeof(client_sock));
    ERROR_CHECK(ret,-1,"connect");

    while(1){
        fd_set set;
        //对set进行初始化
        FD_ZERO(&set);
        //把两个要监听的放到监听列表
        FD_SET(STDIN_FILENO,&set);
        FD_SET(socket_fd,&set);
        select(socket_fd+1,&set,NULL,NULL,NULL);

        if(FD_ISSET(STDIN_FILENO,&set)){
            char buf[100]={0};
            read(STDIN_FILENO,buf,sizeof(buf));
            send(socket_fd,buf,sizeof(buf),0);

        }
        if(FD_ISSET(socket_fd,&set)){
            char buf[100]={0};
            ssize_t ret=recv(socket_fd,buf,sizeof(buf),0);
            if(ret==0){
                break;
            }
            printf("buf%s\n",buf);

        }}
    close(socket_fd);
    return 0;
}

